home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libcruft / linpack / zgeco.f < prev    next >
Text File  |  1996-07-19  |  6KB  |  202 lines

  1.       subroutine zgeco(a,lda,n,ipvt,rcond,z)
  2.       integer lda,n,ipvt(1)
  3.       complex*16 a(lda,1),z(1)
  4.       double precision rcond
  5. c
  6. c     zgeco factors a complex*16 matrix by gaussian elimination
  7. c     and estimates the condition of the matrix.
  8. c
  9. c     if  rcond  is not needed, zgefa is slightly faster.
  10. c     to solve  a*x = b , follow zgeco by zgesl.
  11. c     to compute  inverse(a)*c , follow zgeco by zgesl.
  12. c     to compute  determinant(a) , follow zgeco by zgedi.
  13. c     to compute  inverse(a) , follow zgeco by zgedi.
  14. c
  15. c     on entry
  16. c
  17. c        a       complex*16(lda, n)
  18. c                the matrix to be factored.
  19. c
  20. c        lda     integer
  21. c                the leading dimension of the array  a .
  22. c
  23. c        n       integer
  24. c                the order of the matrix  a .
  25. c
  26. c     on return
  27. c
  28. c        a       an upper triangular matrix and the multipliers
  29. c                which were used to obtain it.
  30. c                the factorization can be written  a = l*u  where
  31. c                l  is a product of permutation and unit lower
  32. c                triangular matrices and  u  is upper triangular.
  33. c
  34. c        ipvt    integer(n)
  35. c                an integer vector of pivot indices.
  36. c
  37. c        rcond   double precision
  38. c                an estimate of the reciprocal condition of  a .
  39. c                for the system  a*x = b , relative perturbations
  40. c                in  a  and  b  of size  epsilon  may cause
  41. c                relative perturbations in  x  of size  epsilon/rcond .
  42. c                if  rcond  is so small that the logical expression
  43. c                           1.0 + rcond .eq. 1.0
  44. c                is true, then  a  may be singular to working
  45. c                precision.  in particular,  rcond  is zero  if
  46. c                exact singularity is detected or the estimate
  47. c                underflows.
  48. c
  49. c        z       complex*16(n)
  50. c                a work vector whose contents are usually unimportant.
  51. c                if  a  is close to a singular matrix, then  z  is
  52. c                an approximate null vector in the sense that
  53. c                norm(a*z) = rcond*norm(a)*norm(z) .
  54. c
  55. c     linpack. this version dated 08/14/78 .
  56. c     cleve moler, university of new mexico, argonne national lab.
  57. c
  58. c     subroutines and functions
  59. c
  60. c     linpack zgefa
  61. c     blas zaxpy,zdotc,zdscal,dzasum
  62. c     fortran dabs,dmax1,dcmplx,dconjg
  63. c
  64. c     internal variables
  65. c
  66.       complex*16 zdotc,ek,t,wk,wkm
  67.       double precision anorm,s,dzasum,sm,ynorm
  68.       integer info,j,k,kb,kp1,l
  69. c
  70.       complex*16 zdum,zdum1,zdum2,csign1
  71.       double precision cabs1
  72.       double precision dreal,dimag
  73.       complex*16 zdumr,zdumi
  74.       dreal(zdumr) = zdumr
  75.       dimag(zdumi) = (0.0d0,-1.0d0)*zdumi
  76.       cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum))
  77.       csign1(zdum1,zdum2) = cabs1(zdum1)*(zdum2/cabs1(zdum2))
  78. c
  79. c     compute 1-norm of a
  80. c
  81.       anorm = 0.0d0
  82.       do 10 j = 1, n
  83.          anorm = dmax1(anorm,dzasum(n,a(1,j),1))
  84.    10 continue
  85. c
  86. c     factor
  87. c
  88.       call zgefa(a,lda,n,ipvt,info)
  89. c
  90. c     rcond = 1/(norm(a)*(estimate of norm(inverse(a)))) .
  91. c     estimate = norm(z)/norm(y) where  a*z = y  and  ctrans(a)*y = e .
  92. c     ctrans(a)  is the conjugate transpose of a .
  93. c     the components of  e  are chosen to cause maximum local
  94. c     growth in the elements of w  where  ctrans(u)*w = e .
  95. c     the vectors are frequently rescaled to avoid overflow.
  96. c
  97. c     solve ctrans(u)*w = e
  98. c
  99.       ek = (1.0d0,0.0d0)
  100.       do 20 j = 1, n
  101.          z(j) = (0.0d0,0.0d0)
  102.    20 continue
  103.       do 100 k = 1, n
  104.          if (cabs1(z(k)) .ne. 0.0d0) ek = csign1(ek,-z(k))
  105.          if (cabs1(ek-z(k)) .le. cabs1(a(k,k))) go to 30
  106.             s = cabs1(a(k,k))/cabs1(ek-z(k))
  107.             call zdscal(n,s,z,1)
  108.             ek = dcmplx(s,0.0d0)*ek
  109.    30    continue
  110.          wk = ek - z(k)
  111.          wkm = -ek - z(k)
  112.          s = cabs1(wk)
  113.          sm = cabs1(wkm)
  114.          if (cabs1(a(k,k)) .eq. 0.0d0) go to 40
  115.             wk = wk/dconjg(a(k,k))
  116.             wkm = wkm/dconjg(a(k,k))
  117.          go to 50
  118.    40    continue
  119.             wk = (1.0d0,0.0d0)
  120.             wkm = (1.0d0,0.0d0)
  121.    50    continue
  122.          kp1 = k + 1
  123.          if (kp1 .gt. n) go to 90
  124.             do 60 j = kp1, n
  125.                sm = sm + cabs1(z(j)+wkm*dconjg(a(k,j)))
  126.                z(j) = z(j) + wk*dconjg(a(k,j))
  127.                s = s + cabs1(z(j))
  128.    60       continue
  129.             if (s .ge. sm) go to 80
  130.                t = wkm - wk
  131.                wk = wkm
  132.                do 70 j = kp1, n
  133.                   z(j) = z(j) + t*dconjg(a(k,j))
  134.    70          continue
  135.    80       continue
  136.    90    continue
  137.          z(k) = wk
  138.   100 continue
  139.       s = 1.0d0/dzasum(n,z,1)
  140.       call zdscal(n,s,z,1)
  141. c
  142. c     solve ctrans(l)*y = w
  143. c
  144.       do 120 kb = 1, n
  145.          k = n + 1 - kb
  146.          if (k .lt. n) z(k) = z(k) + zdotc(n-k,a(k+1,k),1,z(k+1),1)
  147.          if (cabs1(z(k)) .le. 1.0d0) go to 110
  148.             s = 1.0d0/cabs1(z(k))
  149.             call zdscal(n,s,z,1)
  150.   110    continue
  151.          l = ipvt(k)
  152.          t = z(l)
  153.          z(l) = z(k)
  154.          z(k) = t
  155.   120 continue
  156.       s = 1.0d0/dzasum(n,z,1)
  157.       call zdscal(n,s,z,1)
  158. c
  159.       ynorm = 1.0d0
  160. c
  161. c     solve l*v = y
  162. c
  163.       do 140 k = 1, n
  164.          l = ipvt(k)
  165.          t = z(l)
  166.          z(l) = z(k)
  167.          z(k) = t
  168.          if (k .lt. n) call zaxpy(n-k,t,a(k+1,k),1,z(k+1),1)
  169.          if (cabs1(z(k)) .le. 1.0d0) go to 130
  170.             s = 1.0d0/cabs1(z(k))
  171.             call zdscal(n,s,z,1)
  172.             ynorm = s*ynorm
  173.   130    continue
  174.   140 continue
  175.       s = 1.0d0/dzasum(n,z,1)
  176.       call zdscal(n,s,z,1)
  177.       ynorm = s*ynorm
  178. c
  179. c     solve  u*z = v
  180. c
  181.       do 160 kb = 1, n
  182.          k = n + 1 - kb
  183.          if (cabs1(z(k)) .le. cabs1(a(k,k))) go to 150
  184.             s = cabs1(a(k,k))/cabs1(z(k))
  185.             call zdscal(n,s,z,1)
  186.             ynorm = s*ynorm
  187.   150    continue
  188.          if (cabs1(a(k,k)) .ne. 0.0d0) z(k) = z(k)/a(k,k)
  189.          if (cabs1(a(k,k)) .eq. 0.0d0) z(k) = (1.0d0,0.0d0)
  190.          t = -z(k)
  191.          call zaxpy(k-1,t,a(1,k),1,z(1),1)
  192.   160 continue
  193. c     make znorm = 1.0
  194.       s = 1.0d0/dzasum(n,z,1)
  195.       call zdscal(n,s,z,1)
  196.       ynorm = s*ynorm
  197. c
  198.       if (anorm .ne. 0.0d0) rcond = ynorm/anorm
  199.       if (anorm .eq. 0.0d0) rcond = 0.0d0
  200.       return
  201.       end
  202.